<?php
include('functions.php');
db();
function sendEmail($to,$cond=NULL){
$headers = "From: info@outword.org\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

//if($_POST['to'] && $_POST['to']!=""){
	//$to = $_POST['to'];
	
	//tests email via regex function
	if (isEmailValid($to)==TRUE){
	//see if this email address exists
	$useremailqry = dbSelect('users',array("email='$to'"));
		if(mysql_numrows($useremailqry) > 0){
			$userdetails = mysql_fetch_array($useremailqry);
			$userid = $userdetails['id'];
			$founduser=1;
			echo '<br />found user';
		}
		//see if this msgcode exists (preformatted email)
		//if($_POST['msgcode'] && $_POST['msgcode']!=""){
			$msgcode = 'register';//$_POST['msgcode'];
			$emailqry = dbSelect('emails',array("msgcode='$msgcode'"));
			if(mysql_numrows($emailqry) > 0){
				$emailcontent = mysql_fetch_array($emailqry);
				$foundemailcontent= 1; 
				echo '<br />found email content';
			}
		//}
		if($founduser == 1 && $foundemailcontent == 1){
			$subject = '[outword] '.$emailcontent['subject'];
			$body .= $emailcontent['body'];
			echo replaceEmailShortCodes($body,$cond);
			$body = replaceEmailShortCodes($body,$cond);
			
		}

			//mail($to,$subject,$body,$headers,"-finfo@outword.org");
		}else{
			echo '<br />Sorry, but that is not a valid email address. ';
			goBack();	
		}
//}
} //end function
?>